require.config({
    paths: {
        'jquery': 'http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js',
        'vue': '../encaptool/encvue',
        'iview': '../utiltool/iview/iview',
        'bmap': 'http://api.map.baidu.com/api?v=2.0&ak=9whTPxXrl8zvW3gjiAaoPa59gFekKK9I',
        'async': '../utiltool/requirejsplugins/src/async',
        'axios': '../encaptool/encaxios',
        'vueEventCalendar': '../utiltool/vue-event-calendar/index'
    },
    shim: {
        'iview': {
            deps: ['vue']
        },
        'vueEventCalendar': {
            deps: ['vue']
        },
        'bmap': {
            deps: ['jquery'],
            exports: 'BMap'
        }
    }
})

require(['vue', 'iview', 'axios', 'vueEventCalendar', 'jquery', 'async!bmap'], function (Vue, iview, axios, vueEventCalendar) {
    Vue.use(iview);
    Vue.use(vueEventCalendar, {
        locale: 'en'
    });
    var v = new Vue({
        el: '.map-wrapper',
        data() {
            return {
                open: false,
                map: {},
                columns: [{
                    title: '客户名称',
                    key: 'customer'
                },
                {
                    title: '送货地址',
                    key: 'bourn'
                },
                {
                    title: '板材',
                    key: 'board'
                },
                {
                    title: '规格/楞型',
                    key: 'flute'
                },
                {
                    title: '规格型号',
                    key: 'format'
                },
                {
                    title: '面积',
                    key: 'area'
                }, {
                    title: '载重量',
                    key: 'truckload'
                }, {
                    title: '公里',
                    key: 'kilometre'
                }, {
                    title: '运费系数',
                    key: 'coefficient'
                }, {
                    title: '体积',
                    key: 'volume'
                }
                ],
                roadArr: [],
                tabledate: [],
                yfwyLocal: {},
                truckButton: {
                    state: false,
                    type: 'default',
                    loading: false
                },
                bournButton: {
                    state: false,
                    type: 'default',
                    loading: false
                },
                factoryButton: {
                    state: false,
                    type: 'default',
                    loading: false
                },
                obstacleButton: {
                    state: false,
                    type: 'default',
                    loading: false
                },
                searchValue: '',
                searchItems: ['好像没有这个'],
                modal: false,
                modalId: '',
                carname: '',
                cardnum: '',
                carnum: '',
                modalDate: '',
                modalTool: true,
                truckMarkers: [],
                bournMarkers: [],
                factoryMarkers: [],
                factoryCircles: [],
                obstacleMarkers: [],
                truckBournMarkers: [],
                drivingRoute: [],
                allRunInterval: [],
                hasTrckRun: false,
                hasTableValue: false,
                drivingCount: 0,
                saveInfoWindow: {},
                freightId: '',
                // 日历↓
                week: ["日",
                    "一",
                    "二",
                    "三",
                    "四",
                    "五",
                    "六"
                ],
                nowYear: new Date().getFullYear(),
                nowMonth: new Date().getMonth() + 1,
                nowDay: [],
                hasDate: []
            }
        },
        mounted() {
            this.mapInit();
            this.modalInit();
            this.judgeDay();
            this.saveInfoWindow.addEventListener("close", function () {
                this.truckBournMarkers.forEach(function (r) {
                    this.map.removeOverlay(r);
                }.bind(this));
                this.truckBournMarkers = [];
            }.bind(this));
        },
        watch: {
            searchValue: 'getSearchList',
            allRunInterval: function (val) {
                if (val.length) {
                    this.hasTrckRun = true;
                } else {
                    this.hasTrckRun = false;
                }
            },
            tabledate: function (val) {
                if (val.length) {
                    this.hasTableValue = true;
                } else {
                    this.hasTableValue = false;
                }
            },
            nowYear: function () {
                this.judgeDay();
                this.$nextTick(function () {
                    this.judgeHasThisDay();
                });
            },
            nowMonth: function (val, oldVal) {
                if (oldVal == 12 && val == 13) {
                    this.nowMonth = 1;
                    this.nowYear++;
                }
                if (oldVal == 1 && val == 0) {
                    this.nowMonth = 12;
                    this.nowYear--;
                }
                this.judgeDay();
                this.$nextTick(function () {
                    this.judgeHasThisDay();
                });
            }
        },
        methods: {
            // 模态框时间初始化
            modalInit() {
                var date = new Date();
                var year = date.getFullYear();
                var month = (date.getMonth() + 1 < 10) ? ("0" + (date.getMonth() + 1)) : (date.getMonth() + 1);
                var day = (date.getDate() < 10) ? ("0" + date.getDate()) : date.getDate();
                this.modalDate = year + '-' + month + '-' + day;
            },
            // 初始化地图
            mapInit() {
                this.map = new BMap.Map("map");
                this.yfwyLocal = new BMap.Point(116.828624, 40.011752);
                this.map.centerAndZoom(this.yfwyLocal, 12);
                this.map.enableScrollWheelZoom(true);
                this.saveInfoWindow = new BMap.InfoWindow();
            },
            // 显示卡车按钮
            switchTruck() {
                this.truckButton.loading = true;
                this.truckButton.state = !this.truckButton.state;
                this.truckButton.type = this.truckButton.state ? 'primary' : 'default'
                var runFunction = this.truckButton.state ? this.addAllTruck() : this.deleteTruck();
            },
            // 显示配送点按钮
            switchBourn() {
                // this.bournButton.loading = true;
                // this.bournButton.state = !this.bournButton.state;
                // this.bournButton.type = this.bournButton.state ? 'primary' : 'default'
                // var bournButton = this.bournButton.state ? this.addAllBourn() : this.deleteBourn();
                axios.call(this, function (res) {
                    if (res.code === 0) {
                        this.showRoad(res.data)
                    } else {
                        this.$Message.info("未查到数据");
                    }
                }.bind(this), {
                        setting: {
                            method: "GET",
                            url: "/YF/public/api/getwaitdata"
                        }
                    });
            },
            //显示未完成订单的路径
            showRoad(data) {
                for (let i in data) {
                    this.roadArr.push(this.baiduRoad(data[i]['customer'], data[i]['bourn']))
                }
                this.map.centerAndZoom(new BMap.Point(116.508328,39.919141), 11);
                var p1 = new BMap.Point(116.805226,39.976245);
                var p2 = new BMap.Point(116.508328,39.919141);
                var driving = new BMap.DrivingRoute(this.map, { renderOptions: { map: this.map, autoViewport: true } });
                driving.search(p1, p2);
            },
            baiduRoad(customer, bourn) {
                let bournArr = [];
                let cusArr = [];
                var point = new BMap.Point(138.331398, 85.897445);
                let map = this.map
                map.enableScrollWheelZoom(true);
                map.centerAndZoom(point, 12);
                // 创建地址解析器实例
                var myGeo = new BMap.Geocoder();
                // 将地址解析结果显示在地图上,并调整地图视野
                myGeo.getPoint(customer, function (point) {
                    if (point) {
                        map.centerAndZoom(point, 16);

                        cusArr.push(point.lng)
                        cusArr.push(point.lat)
                    } else {
                        alert("您选择地址没有解析到结果!");
                    }
                }, "北京市");
                myGeo.getPoint(bourn, function (point) {
                    if (point) {
                        map.centerAndZoom(point, 16);
                        bournArr.push(point.lng)
                        bournArr.push(point.lat)
                    } else {
                        alert("您选择地址没有解析到结果!");
                    }
                }, "北京市");
                let reslut = {
                    bourn: bournArr,
                    cust: cusArr
                }
                return reslut
            },
            turnAPI(bourn) {
                let setting = {
                    method: 'get',
                    url: "http://api.map.baidu.com/geocoder/v2/?address='" + bourn + "'&output=json&ak=KGfm6dmwE9ek2IZtj9mRPcOZ8mIbMo7c"
                }
                axios.call(this, function (res) {
                    console.log(res)
                }.bind(this), {
                        setting: setting
                    })
            },
            // 显示厂区
            switchFactory() {
                this.factoryButton.loading = true;
                this.factoryButton.state = !this.factoryButton.state;
                this.factoryButton.type = this.factoryButton.state ? 'primary' : 'default'
                var factoryButton = this.factoryButton.state ? this.addAllFactory() : this.deleteFactory();
            },
            // 显示障碍点()
            switchObstacle() {
                this.obstacleButton.loading = true;
                this.obstacleButton.state = !this.obstacleButton.state;
                this.obstacleButton.type = this.obstacleButton.state ? 'primary' : 'default';
                var obstacleButton = this.obstacleButton.state ? this.addAllObstacle() : this.deleteObstacle();
            },
            // 添加障碍点
            addAllObstacle() {
                axios.call(this, function (res) {
                    if (res.code === 0) {
                        this.obstacleButton.loading = false;
                        res.data.forEach((r) => {
                            var points = [];
                            points.push(new BMap.Point(r.longitude, r.latitude));

                            var convertor = new BMap.Convertor();
                            convertor.translate(points, 3, 5, function (data) {
                                if (data.status === 0) {
                                    data.points.forEach((r) => {
                                        this.addOneObstacle(r);
                                    });

                                }
                            }.bind(this));
                        });
                    } else {
                        this.obstacleButton.loading = false;
                        this.$Message.info('当前地图上没有障碍点。');
                        //  this.obstacleButton.type = this.obstacleButton.state ? 'primary' : 'default';
                    }
                }.bind(this), {
                        setting: {
                            method: "GET",
                            url: "/YF/public/api/putTruckObstacle"
                        }
                    })
            },
            addOneObstacle(point) {
                var icon = new BMap.Icon("/YF/public/static/img/obstacle.png", new BMap.Size(48, 48));
                var marker = new BMap.Marker(point, {
                    icon: icon
                });
                this.map.addOverlay(marker);
                this.obstacleMarkers.push(marker);
            },
            deleteObstacle() {
                this.obstacleMarkers.forEach(function (obstacleMarker) {
                    this.map.removeOverlay(obstacleMarker);
                }.bind(this))
                this.obstacleMarkers = [];
                this.obstacleButton.loading = false;
            },
            // 添加厂区
            addAllFactory() {
                axios.call(this, function (res) {
                    if (res.code === 0) {
                        res.data.forEach(function (r) {
                            var point = new BMap.Point(r.longitude, r.latitude);
                            this.addOneFactory(point);
                        }.bind(this));
                        this.factoryButton.loading = false;
                    } else {
                        this.$Message.info('当前地图上没有厂区。');
                        this.factoryButton.loading = false;
                    }
                }.bind(this), {
                        setting: {
                            url: "/YF/public/api/getFactory",
                            method: "GET"
                        }
                    })
            },
            addOneFactory(point) {
                var icon = new BMap.Icon("/YF/public/static/img/marker1.png", new BMap.Size(30, 30));
                var marker = new BMap.Marker(point, {
                    icon: icon
                });
                this.map.addOverlay(marker);
                marker.addEventListener("click", function () {
                    var hasCircles = 1;
                    this.factoryCircles.forEach(function (circle, index) {
                        if (circle.id === 1) {
                            hasCircles = 0;
                            this.map.removeOverlay(circle.circle);
                            this.factoryCircles.splice(index, 1);
                        }
                    }.bind(this));
                    if (hasCircles) {
                        var circle = new BMap.Circle(this.yfwyLocal, 100000, {
                            strokeColor: "blue",
                            strokeWeight: 2,
                            strokeOpacity: 0.5
                        }); //创建圆
                        this.map.addOverlay(circle);
                        this.factoryCircles.push({
                            id: 1,
                            circle: circle
                        });
                    }
                }.bind(this));
                this.map.setZoom(15);
                this.map.panTo(this.yfwyLocal);
                this.factoryMarkers.push(marker);
            },
            // 删除厂区
            deleteFactory() {
                this.factoryMarkers.forEach(function (factoryMarker) {
                    this.map.removeOverlay(factoryMarker);
                }.bind(this))
                this.factoryCircles.forEach(function (factoryCircle) {
                    this.map.removeOverlay(factoryCircle.circle);
                }.bind(this));
                this.factoryMarkers = [];
                this.factoryCircles = [];
                this.factoryButton.loading = false;
            },
            showTruckAndBourns(val) {
                this.truckMarkers.forEach(function (r) {
                    if (r._truckid === val) {
                        r._addEventListener();
                    }
                }.bind(this));
            },
            flashAllTruck() {
                this.deleteTruck();
                this.addAllTruck();
            },
            // 地图添加全部卡车点
            addAllTruck() {
                var truckSetting = {
                    method: 'GET',
                    url: "/YF/public/api/getTruckAtMap"
                }
                axios.call(this, function (res) {
                    if (res.code === 0) {
                        res.data.forEach(function (p) {
                            var truckid = p.truckid;
                            this.getOneTruckLine(truckid);
                        }.bind(this));
                        this.truckButton.loading = false;
                    } else {
                        this.$Message.info('当前地图上没有车主送货。');
                        this.truckButton.loading = false;
                    }
                }.bind(this), {
                        setting: truckSetting
                    })
            },
            // 删除地图卡车点
            deleteTruck() {
                this.allRunInterval.forEach(function (runInterval) {
                    clearInterval(runInterval.runInterval);
                    this.map.removeOverlay(runInterval.carMk);
                }.bind(this))
                this.allRunInterval = [];
                this.truckButton.loading = false;
            },
            // 获得一条卡车线路
            getOneTruckLine(truckid) {
                if (this.drivingRoute.indexOf(truckid) !== -1) {
                    return;
                }
                var OneTruckSetting = {
                    method: 'get',
                    url: "/YF/public/api/getOneTruckAtMap/" + truckid
                }
                axios.call(this, function (data) {
                    if (data.code === 400) {
                        return;
                    }
                    var longitude = data.data.longitude;
                    var latitude = data.data.latitude;
                    var truck = new BMap.Point(longitude, latitude);
                    var convertor = new BMap.Convertor();
                    convertor.translate([truck], 3, 5, function (data) {
                        if (data.status === 0) {
                            truck = data.points[0];
                            var icon = new BMap.Icon("/YF/public/static/img/runtruck.png", new BMap.Size(30, 30));
                            var carMk = new BMap.Marker(truck, {
                                icon: icon
                            });
                            var self = this;
                            this.map.addOverlay(carMk);

                            function toAddEventListener() {
                                var carSelf = this;
                                var setting = {
                                    method: 'GET',
                                    url: "/YF/public/api/getOrderIdByTruckId/" + truckid
                                }
                                self.getDate(function (data) {
                                    console.log(data);
                                    var tid = "'" + truckid + "'";
                                    var content = '<ul class="alert"><li><h3>' + truckid + '</h3></li><li>车主姓名:<span>' + data.name + '</span></li><li>车主姓名:<span>' + data.phone + '</span></li><li>当前送货单号:<span><a onclick="showOrderlist(' + data.phone + ')">' + data.freightId + '</a></span></li></li><li>已运送厂区:<span>' + data.dnum + '</span></li></li><li>已运送订单:<span>' + data.num + '</span></li><li style="text-align:right"><a onclick="mClick(' + tid + ')">追踪</a></li></ul>';

                                    this.truckBournMarkers.forEach(function (r) {
                                        this.map.removeOverlay(r);
                                    }.bind(this));
                                    this.truckBournMarkers = [];
                                    axios.call(this, function (res) {
                                        if (res.code === 0) {
                                            res.data.forEach(function (r) {
                                                var point = new BMap.Point(r.longitude, r.latitude);
                                                var icon = new BMap.Icon("/YF/public/static/img/marker1.png", new BMap.Size(30, 30));
                                                var marker = new BMap.Marker(point, {
                                                    icon: icon
                                                });
                                                this.truckBournMarkers.push(marker);
                                                this.map.addOverlay(marker);
                                            }.bind(this));
                                        }
                                    }.bind(this), {
                                            setting: {
                                                method: 'GET',
                                                url: "/YF/public/api/getSendingbournByTruckid/" + truckid
                                            }
                                        });
                                    this.saveInfoWindow.setContent(content);
                                    carSelf.openInfoWindow(this.saveInfoWindow, {
                                        offset: new BMap.Size(0, 0)
                                    });
                                }.bind(self), setting);
                            }
                            carMk._truckid = truckid;
                            carMk._addEventListener = toAddEventListener;
                            carMk.addEventListener("click", toAddEventListener)
                            this.truckMarkers.push(carMk);
                            var truckPoint = [];
                            var polyline = {};
                            function truckRun() {
                                axios.call(this, function (data) {
                                    var newPoint = new BMap.Point(data.data.longitude, data.data.latitude);
                                    convertor.translate([newPoint], 3, 5, function (data) {
                                        if (data.status != 0) {
                                            return;
                                        }
                                        newPoint = data.points[0];
                                        truckPoint.push(newPoint);
                                        carMk.setPosition(newPoint);
                                    }.bind(this));
                                }.bind(this), {
                                        setting: OneTruckSetting
                                    })
                            }
                            var runInterval = setInterval(truckRun.bind(this), 300000);
                            this.allRunInterval.push({
                                truckid: truckid,
                                runInterval: runInterval,
                                carMk: carMk
                            });
                            this.drivingCount = this.allRunInterval.length;
                        }
                    }.bind(this));
                }.bind(this), {
                        setting: OneTruckSetting
                    });
            },
            // 清除一条卡车线路 有不是的
            clearOneTruckLine(truckid) {
                this.allRunInterval.forEach(function (runInterval, index) {
                    if (runInterval.truckid === truckid) {
                        clearInterval(runInterval.runInterval);
                        this.map.removeOverlay(runInterval.carMk);
                        this.allRunInterval.splice(index, 1);
                        this.drivingCount = this.allRunInterval.length;
                        if (this.drivingCount == 0) {
                            this.truckButton.type = 'default';
                            this.truckButton.state = !this.truckButton.state;
                        }
                    }
                }.bind(this));
            },
            // 添加全部厂区 有数据
            addAllBourn() {
                var bournSetting = {
                    method: 'GET',
                    url: "/YF/public/api/getBournAtMap"
                }
                axios.call(this, function (point) {
                    if (point.code === 0) {
                        point.data.forEach(function (p) {
                            var bournid = p.bournid;
                            var latitude = p.latitude;
                            var longitude = p.longitude;
                            var name = p.bournname;
                            var onePoint = new BMap.Point(longitude, latitude);
                            this.addTheBourn(bournid, onePoint, name);
                        }.bind(this));
                        this.bournButton.loading = false;
                    } else {
                        this.$Message.info("当前没有配送点。");
                        this.bournButton.loading = false;
                    }
                }.bind(this), {
                        setting: bournSetting
                    });
            },
            // 添加单个厂区
            addTheBourn(bournid, point, name) {
                var icon = new BMap.Icon("/YF/public/static/img/marker0.png", new BMap.Size(30, 30));
                var marker = new BMap.Marker(point, {
                    icon: icon
                });
                this.map.addOverlay(marker);
                // var label = new BMap.Label(name, { offset: new BMap.Size(-15, 20) });
                // marker.setLabel(label);
                var self = this;
                marker.addEventListener("click", function () {
                    var carSelf = this;
                    var setting = {
                        method: 'post',
                        url: "/YF/public/api/getBournOrderNumByName"
                    }
                    var data = {
                        'bourn': name,
                    }
                    axios.call(self, function (res) {
                        if (res.code === 0) {
                            var content = '<ul class="alert"><li><h2>' + name + '</h2></li><li><h3>收货次数:' + res.data + '</h3></li></ul>'
                            var infoWindow = new BMap.InfoWindow(content);
                            carSelf.openInfoWindow(infoWindow, {
                                offset: new BMap.Size(0, 0)
                            });
                        } else {
                            var content = '<ul class="alert"><li><h2>' + name + '</h2></li><li><h3>收货次数:' + 1 + '</h3></li></ul>'
                            var infoWindow = new BMap.InfoWindow(content);
                            carSelf.openInfoWindow(infoWindow, {
                                offset: new BMap.Size(0, 0)
                            });
                        }
                    }.bind(self), {
                            setting,
                            data
                        })
                });
                //     var setting = {
                //         method: 'GET',
                //         url: "/YF/public/api/getOrderIdByTruckId/" + bournid
                //     }
                //     this.getDate(function (data) {
                //         this.$Notice.info({
                //             title: truckid,
                //             desc: '<ul><li>车主姓名:' + data.name + '</li><li>当前订单:' + data.freightId + '</li></ul>'
                //         });
                //     }.bind(this), setting);

                // }.bind(this))
                this.bournMarkers.push(marker);
            },
            // 删除地图厂区点
            deleteBourn() {
                this.bournMarkers.forEach(function (bournMarker) {
                    this.map.removeOverlay(bournMarker);
                }.bind(this))
                this.bournMarkers = [];
                this.bournButton.loading = false;
            },
            getmap() {
                //设置标注的图标
                var icon = new BMap.Icon("/YF/public/static/img/deliveryPoint.png", new BMap.Size(100, 100));
                for (i = 0; i < this.point.length; i++) {
                    var yfps = new BMap.Point(this.point[i].longitude, this.point[i].latitude);
                    //设置标注的经纬度
                    var marker = new BMap.Marker(new BMap.Point(this.point[i].longitude, this.point[i].latitude), {
                        icon: icon
                    });
                    //把标注添加到地图上
                    this.map.addOverlay(marker);
                }
                var icon = new BMap.Icon("/YF/public/static/img/sign.png", new BMap.Size(100, 100));
                //设置标注的经纬度
                var marker1 = new BMap.Marker(new BMap.Point(116.828624, 40.011752), {
                    icon: icon
                });
                //把标注添加到地图上
                this.map.addOverlay(marker1);
                var circle = new BMap.Circle(this.yfwyLocal, 100000, {
                    strokeColor: "blue",
                    strokeWeight: 2,
                    strokeOpacity: 0.5
                }); //创建圆
                this.map.addOverlay(circle);
            },
            getDate(callback, setting) {
                axios.call(this, function (res) {
                    if (res.code === 0) {
                        var data = res.data;
                        callback(data);
                    } else {
                        this.$Message.error('功能加载错误');
                        this.truckButton = false;
                    }
                }.bind(this), {
                        setting
                    });
            },
            // 不是
            getSearchList(val, oldVal) {
                var searchSetting = {
                    method: 'GET',
                    url: "/YF/public/api/getTruckIdByTruckId/" + val
                }
                if (val) {
                    this.getDate(function (data) {
                        this.searchItems = data.slice(0, 10);
                    }.bind(this), searchSetting);
                }
            },
            // 清除所有图层
            clearAllLayer() {
                this.map.clearOverlays();
                this.bournButton.state = false;
                this.factoryButton.state = false;
                this.truckButton.state = false;
                this.obstacleButton.state = false;
                this.bournButton.type = this.bournButton.state ? 'primary' : 'default';
                this.factoryButton.type = this.factoryButton.state ? 'primary' : 'default';
                this.truckButton.type = this.truckButton.state ? 'primary' : 'default';
                this.obstacleButton.type = this.obstacleButton.state ? 'primary' : 'default';
                this.truckMarkers = [];
                this.bournMarkers = [];
                this.factoryMarkers = [];
                this.factoryCircles = [];
                this.allRunInterval.forEach(function (runInterval) {
                    clearInterval(runInterval.runInterval);
                })
                this.allRunInterval = [];
                this.drivingRoute = [];
            },
            // 获得卡车位置
            locationTruckById(truckid) {
                this.allRunInterval.forEach(function (route) {
                    if (route.truckid === truckid) {
                        this.map.panTo(route.carMk.point);
                        this.map.setZoom(15);
                    }
                }.bind(this));
            },
            // 点击模态框 all_data
            modalClick(option) {
                this.tabledate = []
                this.modalTool = true;
                this.modal = true;
                this.modalId = option;
                this.open = true;
                var setting = {
                    method: 'get',
                    url: '/YF/public/api/getCreateDateByTruckid/' + option,
                }
                this.listOrderInfo(this.modalId);
                this.getDate(function (data) {
                    this.hasDate = [];
                    this.hasDate = data;
                    this.judgeHasThisDay();
                }.bind(this), setting);
            },
            // all_data
            orderInfo() {
                var setting = {
                    method: 'post',
                    url: '/YF/public/api/getOneDayByTurckIdAndDate/',
                }
                var data = {
                    'truckid': this.modalId,
                    'createdate': this.modalDate
                }
                axios.call(this, function (res) {
                    if (res.code === 0) {
                        this.tabledate = res.data;
                        //this.modalTool = !this.modalTool;
                    } else {
                        this.$Message.info('该车辆当天没有运输货物');
                        this.tabledate = null;
                    }
                }.bind(this), {
                        setting,
                        data
                    })
            },
            // all_data
            listOrderInfo(truckid) {
                var setting = {
                    method: 'get',
                    url: '/YF/public/api/getOrderIdByTruckId/' + truckid,
                }
                axios.call(this, function (res) {
                    if (res.code === 0) {
                        var freightId;
                        if (res.data.freightId) {
                            freightId = res.data.freightId;
                            this.carname = res.data.name;
                            this.cardnum = res.data.dnum;
                            this.carnum = res.data.num;
                        } else {
                            freightId = '当前没有接单';
                        }
                    } else {
                        this.$Message.error('网络出现问题,请重试');
                    }
                }.bind(this), {
                        setting
                    })
            },
            addOneBourn(point) { },
            setOrderlocation() {
                if (!this.tabledate.length) {
                    return;
                }
                var arr = [];
                for (var i = 0; i < this.tabledate.length - 1; i++) {
                    if (this.tabledate[i].bourn != this.tabledate[i + 1].bourn) {
                        arr.push(i);
                    }
                }
                arr.push(this.tabledate.length - 1);
                if (arr.length === 1) {
                    var one = this.tabledate[0];
                    var point = new BMap.Point(one.longitude, one.latitude);
                    var icon = new BMap.Icon("/YF/public/static/img/marker6.png", new BMap.Size(30, 30));
                    var marker = new BMap.Marker(point, {
                        icon: icon
                    });
                    this.map.addOverlay(marker);
                    var content = '<div id="info-window">';
                    this.tabledate.forEach(function (td) {
                        content += '<ul class="alert"><li><h3>' + td.freightId + '</h3></li><li>客户名称:<span>' + td.customer + '</span></li><li>送货地址:<span>' + td.bourn + '</span></li><li> 板材: <span>' + td.board + '</span></li ><li> 规格/楞型: <span>' + td.flute + '</span></li><li> 规格型号: <span>' + td.format + '</span></li><li> 面积: <span>' + td.area + '</span></li><li> 载重量: <span>' + td.truckload + '</span></li><li> 公里: <span>' + td.kilometre + '</span></li><li> 运费系数: <span>' + td.coefficient + '</span></li><li> 体积: <span>' + td.volume + '</span></li></ul>';
                    })
                    content += '</div>';
                    marker.addEventListener('click', function () {
                        this.saveInfoWindow.setContent(content);
                        this.map.openInfoWindow(this.saveInfoWindow, point, {
                            offset: new BMap.Size(0, 0)
                        });
                    }.bind(this));
                    var viewport = this.map.getViewport([point]);
                    this.map.centerAndZoom(viewport.center, viewport.zoom);
                } else {
                    var marker = [];
                    var content = [];
                    var point = [];
                    for (var i = 0; i < arr.length; i++) {
                        (function (i) {
                            content[i] = '<div id="info-window">';
                            if (i === 0) {
                                var one = this.tabledate[0];
                                point.push(new BMap.Point(one.longitude, one.latitude));
                                var icon = new BMap.Icon("/YF/public/static/img/marker6.png", new BMap.Size(30, 30));
                                marker.push(new BMap.Marker(point[i], {
                                    icon: icon
                                }));
                                this.map.addOverlay(marker[i]);
                                for (let j = 0; j < arr[i]; j++) {
                                    content[i] += '<ul class="alert"><li><h3>' + one.freightId + '</h3></li><li>客户名称:<span>' + one.customer + '</span></li><li>送货地址:<span>' + one.bourn + '</span></li><li> 板材: <span>' + one.board + '</span></li ><li> 规格/楞型: <span>' + one.flute + '</span></li><li> 规格型号: <span>' + one.format + '</span></li><li> 面积: <span>' + one.area + '</span></li><li> 载重量: <span>' + one.truckload + '</span></li><li> 公里: <span>' + one.kilometre + '</span></li><li> 运费系数: <span>' + one.coefficient + '</span></li><li> 体积: <span>' + one.volume + '</span></li></ul>';
                                }
                            } else {
                                var one = this.tabledate[arr[i]];
                                point.push(new BMap.Point(one.longitude, one.latitude));
                                var icon = new BMap.Icon("/YF/public/static/img/marker6.png", new BMap.Size(30, 30));
                                marker.push(new BMap.Marker(point[i], {
                                    icon: icon
                                }));
                                this.map.addOverlay(marker[i]);
                                for (let j = arr[i - 1]; j < arr[i]; j++) {
                                    content[i] += '<ul class="alert"><li><h3>' + one.freightId + '</h3></li><li>客户名称:<span>' + one.customer + '</span></li><li>送货地址:<span>' + one.bourn + '</span></li><li> 板材: <span>' + one.board + '</span></li ><li> 规格/楞型: <span>' + one.flute + '</span></li><li> 规格型号: <span>' + one.format + '</span></li><li> 面积: <span>' + one.area + '</span></li><li> 载重量: <span>' + one.truckload + '</span></li><li> 公里: <span>' + one.kilometre + '</span></li><li> 运费系数: <span>' + one.coefficient + '</span></li><li> 体积: <span>' + one.volume + '</span></li></ul>';
                                }
                            }
                            content[i] += '</div>';
                            var self = this;
                            marker[i].addEventListener('click', function () {
                                var carSelf = this;
                                self.saveInfoWindow.setContent(content[i]);
                                carSelf.openInfoWindow(self.saveInfoWindow, {
                                    offset: new BMap.Size(0, 0)
                                });
                            });
                        }.bind(this))(i);

                    }
                    var viewport = this.map.getViewport(point);
                    this.map.centerAndZoom(viewport.center, viewport.zoom);
                }
                // this.tabledate.forEach(function (one) {
                //     var point = new BMap.Point(one.longitude, one.latitude);
                //     var icon = new BMap.Icon("/YF/public/static/img/marker6.png", new BMap.Size(30, 30));
                //     var marker = new BMap.Marker(point, {
                //         icon: icon
                //     });
                //     this.map.addOverlay(marker);
                //     marker.addEventListener('click',function () {
                //         var content = '<ul><li><h3>' + one.freightId + '</h3></li><li>客户名称:<span>' + one.customer + '</span></li><li>送货地址:<span>' + one.bourn + '</span></li><li> 板材: <span>' + one.board + '</span></li ><li> 规格/楞型: <span>' + one.flute + '</span></li><li> 规格型号: <span>' + one.format + '</span></li><li> 面积: <span>' + one.area + '</span></li><li> 载重量: <span>' + one.truckload + '</span></li><li> 公里: <span>' + one.kilometre + '</span></li><li> 运费系数: <span>' + one.coefficient + '</span></li><li> 体积: <span>' + one.volume + '</span></li></ul>';
                //         this.saveInfoWindow.setContent(content);
                //         this.map.openInfoWindow(this.saveInfoWindow, point, {
                //             offset: new BMap.Size(0, 0)
                //         });
                //     }.bind(this))
                // }.bind(this))
            },
            handleChange(date) {
                this.modalDate = date;
                this.orderInfo();
            },
            /* 日历 */
            // 向日历添加日期
            setDay(num) {
                this.nowDay = [];
                var spaceNum = new Date(this.nowYear + "-" + this.nowMonth + "-" + "01").getDay();
                if (spaceNum != 0) {
                    for (var i = 1; i <= 7 - spaceNum; i++) {
                        this.nowDay.push(" ");
                    }
                }
                for (var i = 1; i <= num; i++) {
                    this.nowDay.push(i);
                }
                if (this.nowDay.length <= 28) {
                    var lastSpace = 0;
                } else if (this.nowDay.length <= 35) {
                    var lastSpace = 35 - this.nowDay.length;
                } else {
                    var lastSpace = 42 - this.nowDay.length;
                }
                for (var i = 1; i <= lastSpace; i++) {
                    this.nowDay.push(" ");
                }
            },
            // 判断月份天数
            judgeDay() {
                //判断是否是闰年
                if ((this.nowYear % 4 == 0 && this.nowYear % 100 != 0) || this.nowYear % 400 == 0) {
                    //是闰年
                    //判断是不是二月
                    if (this.nowMonth == 2) {
                        this.setDay(29);
                    } else {
                        switch (this.nowMonth) {
                            case 2:
                            case 4:
                            case 6:
                            case 9:
                            case 11:
                                this.setDay(30);
                                break;
                            default:
                                this.setDay(31);
                                break;
                        }
                    }
                } else {
                    //判断是不是二月
                    if (this.nowMonth == 2) {
                        this.setDay(28);
                    } else {
                        switch (this.nowMonth) {
                            case 2:
                            case 4:
                            case 6:
                            case 9:
                            case 11:
                                this.setDay(30);
                                break;
                            default:
                                this.setDay(31);
                                break;
                        }
                    }
                }
            },
            // 判断该日期
            judgeHasThisDay() {
                var dayBlock = document.getElementsByClassName("day-block");
                for (var i = 0; i < dayBlock.length; i++) {
                    dayBlock[i].style.backgroundColor = "#ffffff";
                    dayBlock[i].style.color = "#bfbfbf";
                    dayBlock[i].disabled = true;
                }
                for (var i = 0; i < this.hasDate.length; i++) {
                    var nowDate = this.hasDate[i].createdate;
                    var a = document.getElementById(nowDate);
                    if (a) {
                        a.style.backgroundColor = "#2face8db";
                        a.style.color = "#ffffff";
                        a.disabled = false;
                    }
                }
            },
            getDateId(nowYear, nowMonth, d) {
                if (nowMonth < 10) {
                    nowMonth = '0' + nowMonth;
                }
                if (d < 10) {
                    d = '0' + d;
                }
                return nowYear + '-' + nowMonth + '-' + d;
            }

        }
    });
    window.mClick = function (id) {
        v.modalClick(id);
    }
    window.showOrderlist = function (phone) {
        axios.call(this, function (res) {
            if (res.code === 0) {
                var title = '';
                var text = '<table class="alert-table"><tr><th>订单号</th><th>目的地</th><th>板材</th><th>体积</th></tr>'
                res.data.datalist.forEach(function (r) {
                    title = r.freightId;
                    text += '<tr><td>' + r.orderid + '</td><td>' + r.bourn + '</td><td>' + r.board + '</td><td>' + r.volume + '</td></tr>';
                });
                text += '</table>';
                v.$Modal.info({
                    title: title,
                    content: text
                })
            }
        }, {
                setting: {
                    method: 'POST',
                    url: "/YF/public/api/getAlreadyOrderInfo"
                },
                data: {
                    phone
                }
            })
    }
});